home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
008
/
egagraph.arc
/
BOX.ASM
next >
Wrap
Assembly Source File
|
1987-07-23
|
8KB
|
280 lines
; BOX.ASM EGA box drawing routine
; Box(x1,y1,x2,y2 : INTEGER; Fill : BOOLEAN; Color : INTEGER);
; (x1,y2) is the upper left corner
; (x2,y2) is the lower right corner
; This routine is designed to be called from Turbo Pascal.
; It has been tested on both EGA and 640x480 modes on the
; Video 7 graphics board. If you find a way to make it faster,
; let me know.
; James Billmeyer
; Soft-Touch Computer Systems
; 7716 Balboa Blvd., Unit D
; Van Nuys, Ca. 91406
; (818) 781-4400
cseg segment byte ; start of code segment
assume cs:cseg
; AX = general use
; BL = Mask
; BH = Color
; CX = delx (or longest dela length -- main loop only)
; DX = (for port output)
; DI = Address1
; SI = Address2
box proc near
; --- Initialization ---
int 1
push bp
mov bp,sp ; get top of stack
mov ax,[bp+10] ; delx := x2 - x1
sub ax,[bp+14]
cmp ax,0 ; if delx < 0 then
jge cdely
neg ax ; delx := abs(delx)
mov bx,[bp+10] ; swap(x1,x2)
xchg bx,[bp+14]
mov [bp+10],bx ; endif
cdely:
mov bx,[bp+8] ; dely := y2 - y1
sub bx,[bp+12]
cmp bx,0
jge initEGA ; else if dely < 0 then
neg bx ; dely := abs(dely)
mov dx,[bp+8] ; swap(y1,y2)
xchg bx,[bp+12]
mov [bp+8],bx ; endif
initEGA:
push bx
push ax
; ---- Initialize EGA Card ----
; Select Write Mode 2
mov dx,3CEh ; select mode register
mov ax,5
out dx,al
mov dx,3CFh ; set to write mode 2
mov ax,2
out dx,al
; Set Bit Mask Register
mov dx,3CEh ; select register 8
mov ax,8
out dx,al
mov dx,0A000h ; es := EGA buffer segment address
mov es,dx
mov ax,[bp+6] ; if filled then
cmp ax,0
jg filled ; HollowBox
pop ax
pop bx
call boxh
jmp lend
filled: ; else
pop ax
pop bx
call boxf ; FilledBox
; endif
lend:
; Restore defualt EGA graphics status
mov dx,3CEh
mov ax,5
out dx,al
mov dx,3CFh
mov ax,0
out dx,al
mov dx,3CEh
mov ax,8
out dx,al
mov dx,3CFh
mov ax,0FFh
out dx,al
pop bp
ret 12
box endp
; --- HollowBox ---
boxh proc near
push bx
push ax
mov ax,[bp+12] ; address1 := (y1 * 80) + (x1 / 8)
mov dx,80
mul dx
mov cx,3
mov di,[bp+14]
shr di,cl
add di,ax
mov ax,[bp+8] ; address2 := (y2 * 80) + (x1 / 8)
mov dx,80
mul dx
mov cx,3
mov si,[bp+14]
shr si,cl
add si,ax
mov cx,[bp+14] ; mask := 1 shl (7 - x mod 8)
and cl,7
xor cl,7
mov ch,1
shl ch,cl
mov bl,ch
mov bh,bl
mov dx,3CFh
pop cx ; for i := 1 to dx do
inc cx
hllp1:
; ---- Plot Point -------------+
; |
mov al,bl ; | output bit mask to register 8
out dx,al ; |
mov al,es:[di] ; | latches all four bit planes
mov ax,[bp+4] ; |
mov es:[di],al ; | set color
mov ah,es:[si] ; | latches all four bit planes
mov es:[si],al ; | set color
; |
; --- end of plot point -------+
ror bl,1 ; x := x + 1
adc di,+00
ror bh,1
adc si,+00
loop hllp1 ; endfor
; --- Calculate addresses for x constant lines ---
mov ax,[bp+12] ; address1 := (y1 * 80) + (x1 / 8)
mov dx,80
mul dx
mov cx,3
mov di,[bp+14]
shr di,cl
add di,ax
mov ax,[bp+12] ; address2 := (y1 * 80) + (x2 / 8)
mov dx,80
mul dx
mov cx,3
mov si,[bp+10]
shr si,cl
add si,ax
mov cx,[bp+14] ; mask := 1 shl (7 - x1 mod 8)
and cl,7
xor cl,7
mov ch,1
shl ch,cl
mov bl,ch
mov cx,[bp+10] ; mask := 1 shl (7 - x2 mod 8)
and cl,7
xor cl,7
mov ch,1
shl ch,cl
mov bh,ch
mov dx,3CFh
pop cx ; for i := 1 to dy do
hllp2:
; ---- Plot Point -------------+
; |
mov al,bl ; | output bit mask to register 8
out dx,al ; |
mov al,es:[di] ; | latches all four bit planes
mov ax,[bp+4] ; |
mov es:[di],al ; | set color
mov al,bh ; | output bit mask to register 8
out dx,al ; |
mov al,es:[si] ; | latches all four bit planes
mov ax,[bp+4] ; |
mov es:[si],al ; | set color
; |
; --- end of plot point -------+
add di,80 ; y := y + 1
add si,80
loop hllp2 ; endfor
ret
boxh endp
; --- Filled Box ---
boxf proc near
push bx
push ax
mov ax,[bp+12] ; address1 := (y1 * 80) + (x1 / 8)
mov dx,80
mul dx
mov cx,3
mov di,[bp+14]
shr di,cl
add di,ax
mov cx,[bp+14] ; mask := 1 shl (7 - x mod 8)
and cl,7
xor cl,7
mov ch,1
shl ch,cl
mov bl,ch
mov bh,bl ; oldmask := mask
mov dx,3CFh
pop cx ; for i := 1 to dx do
pop si
inc si
inc cx
fllp1:
ror bl,1 ; x := x + 1
jc plot ; if NOT MaskFull then
or bh,bl ; oldmask := oldmask or mask
loop fllp1
jmp fend
plot: ; else
xchg cx,si
push cx
mov al,bh ; output bit mask to register 8
out dx,al
mov ax,[bp+4] ; set color
push di ; oldaddress := address
fllp3: ; for i := 1 to dy do
mov ah,es:[di] ; latches all four bit planes (address)
mov es:[di],al ; turn pixels on (address)
add di,80 ; address := address + 80
loop fllp3 ; endfor
pop di ; address := oldaddress
add di,1 ; address := address + 1
mov bh,bl ; oldmask := mask
pop cx
xchg cx,si
; endif
loop fllp1 ; endfor
fend:
mov al,bh ; output bit mask to register 8
out dx,al ;
mov al,es:[di] ; latches all four bit planes (address)
mov ax,[bp+4] ; set color
mov cx,si
fllp4: ; for i := 1 to dy do
mov es:[di],al ; turn pixels on (address)
add di,80 ; address := address + 80
loop fllp4 ; endfor
ret
boxf endp
cseg ends
end